package com.zlt.bkparking.controller.admin;

import com.github.pagehelper.PageInfo;
import com.zlt.bkparking.dto.UserVipDTO;
import com.zlt.bkparking.dto.VipTypeDTO;
import com.zlt.bkparking.service.VIPTypeService;
import com.zlt.bkparking.vo.Result;
import com.zlt.bkparking.vo.UserVipVO;
import com.zlt.bkparking.vo.VipTypeVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Classname VIPTypeController
 * @Description TODO
 * @Date 2022/10/2 15:13
 * @Created by ${Lijijun}
 */
@RequestMapping("vip")
@RestController
public class VIPTypeController {

    @Autowired
    private VIPTypeService vipTypeService;

    @GetMapping("all")
//    @CrossOrigin
    public Result selectVipTypes(){
        List<VipTypeVO> vipTypeVOList =vipTypeService.selectVipTypes();
        return Result.ok("vip类型查询成功",vipTypeVOList);
    }

    @PostMapping("update")
//    @CrossOrigin
    public Result updateVipType(/*@RequestBody*/ VipTypeDTO vipTypeDTO){
        boolean bool =vipTypeService.updateVipType(vipTypeDTO);
        return bool?Result.ok("Vip类型信息更新成功"):Result.error("Vip类型信息更新失败");

    }

    @PostMapping("add")
//    @CrossOrigin
    public Result addVipType(/*@RequestBody*/ VipTypeDTO vipTypeDTO){
        try {
            boolean bool = vipTypeService.insertVipType(vipTypeDTO);
            return  bool?Result.ok("新增Vip类型成功"):Result.error("新增Vip类型失败");
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error(e.getMessage());

        }
    }

    @PostMapping("delete")
//    @CrossOrigin
    public Result deleteVipType(/*@RequestBody*/ VipTypeDTO vipTypeDTO){
        boolean bool=vipTypeService.deleteVipType(vipTypeDTO);
        return bool?Result.ok("Vip类型删除成功"):Result.error("Vip类型删除失败");
    }

//    @GetMapping("vipUsers")
    @PostMapping("vipUsers")
//    @CrossOrigin
    public Result selectVipUsers(UserVipDTO userVipDTO){
        System.out.println("UserVipDTO===>"+userVipDTO);

        PageInfo<UserVipVO> userVipVOList = vipTypeService.selectVipUsers(userVipDTO);
        return Result.ok("Vip用户列表查询成功",userVipVOList);

    }

    @PostMapping("vipUser")
//    @CrossOrigin
    public Result updateVipUser(/*@RequestBody*/ UserVipDTO userVipDTO){
//        System.out.println("UserVipDTO===>"+userVipDTO);
        boolean bool = false;
        try {
            bool = vipTypeService.updateVipUser(userVipDTO);
            return bool?Result.ok("Vip用户的Vip信息修改成功"):Result.error("Vip用户的Vip信息修改失败");
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error(e.getMessage());
        }
    }

    @PostMapping("vipUserState")
//    @CrossOrigin
    public Result updateVipUserState(/*@RequestBody*/ UserVipDTO userVipDTO){
        boolean bool = false;
        try {
            bool = vipTypeService.updateVipUserState(userVipDTO);
            return bool?Result.ok("vip启用或禁用成功"):Result.error("vip启用或禁用失败");
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error(e.getMessage());
        }

    }



}
